home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSCPU.C < prev    next >
C/C++ Source or Header  |  1993-08-08  |  3KB  |  126 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bscpu.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains .
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <bs.h>
  45.  
  46. //----------------------------------------------------------------------------
  47. //   Description:    Determine CPU type.
  48. //    Parameters:
  49. //       Returns:    0 = 8086, 2=286, 3=386, ...
  50. //                        Currently 486+ are not recognized
  51. //----------------------------------------------------------------------------
  52. SIZET FN_E Cpu(void)
  53. {
  54. #if OS_OS2
  55.     return 3;
  56. #elif OS_DOS || OS_WINDOWS
  57.     _asm {
  58.         push    sp                          // Test for 808x, 8018x
  59.       pop     bx
  60.       cmp     sp,bx
  61.       jz      cpu286                       // Not one of earlier 808x or 8018x
  62.       mov     bx,0ffffh
  63.       mov     cl,33
  64.       shl     bx,cl
  65.       or      bx,ax
  66.       jnz     cpu186
  67.         }
  68.     return 0;                                    // 8086
  69.  
  70. cpu186:
  71.     return 1;                                    // 80186
  72.  
  73. cpu286:
  74.     _asm {
  75.         pushf                               // Test for 80286
  76.       pop     bx
  77.       or      bx,4000h
  78.       push    bx
  79.       popf
  80.         pushf
  81.       pop     bx
  82.       test    bx,4000h
  83.       jnz     cpu386
  84.         }
  85.     return 2;                                    // 286
  86. cpu386:
  87.     return 3;                                    // 386
  88. #else
  89.     return 3;                                    // Unix
  90. #endif
  91. }
  92.  
  93. //----------------------------------------------------------------------------
  94. //   Description:    Determine CPU type.
  95. //    Parameters:
  96. //       Returns:    0 = 8086, 2=286, 3=386, ...
  97. //                        Currently 486+ are not recognized
  98. //----------------------------------------------------------------------------
  99. PCSZ FN_E CpuName(void)
  100. {
  101. static PCSZ apcsz[] = { "8086", "80186", "80286", "80386", "80486", "80586" };
  102.     SIZET cCpu = Cpu();
  103.  
  104.     Assert(cCpu <= 5);
  105.     return apcsz[cCpu];
  106. }
  107.  
  108.  
  109. //----------------------------------------------------------------------------
  110. //   Description:    Run standard test suite
  111. //    Parameters:    sTest        Test to run.
  112. //                                        0        Run all default tests (except).
  113. //       Returns:    TRUE if successful.
  114. //----------------------------------------------------------------------------
  115. #if COMPILE_TEST
  116. BOOL FN CpuTest(SHORT sTest)
  117. {
  118.     NOTUSED(sTest);
  119.     Output("CPU is a %s\n", CpuName());
  120.     return TRUE;
  121. }
  122. #endif
  123. //----------------------------------------------------------------------------
  124. //------------------------------- End of File --------------------------------
  125. //----------------------------------------------------------------------------
  126.